bool ST;
#include <bits/stdc++.h>
#define int long long
using namespace std;
constexpr int N = 2e5 + 5;
int n, m;
int rt[N];
vector<pair<int, int>> g[N];
namespace pt {
constexpr int M = N * 40;
struct Node {
    int ls, rs, s, lzy;
} tr[N];
int cnt;
auto clone(int p) {
    tr[++cnt] = tr[p];
    return cnt;
}
void add(int l, int r, int& p, int s, int t, int w) {
    p = clone(p);
    if (l >= s && r <= t) {
        tr[p].s += w;
        tr[p].lzy += w;
        return;
    }
    int mid = l + r >> 1;
    if (mid >= s)
        add(l, mid, tr[p].ls, s, t, w);
    if (mid < t)
        add(mid + 1, r, tr[p].rs, s, t, w);
}
int query(int l, int r, int p1, int p2, int x) {
    if (l == r)
        return tr[p2].s - tr[p1].s;
    int mid = l + r >> 1;
    int res = tr[p2].lzy - tr[p1].lzy;
    if (mid >= x)
        return res + query(l, mid, tr[p1].ls, tr[p2].ls, x);
    return res + query(mid + 1, r, tr[p1].rs, tr[p2].rs, x);
}
}  // namespace pt
namespace hc {
int cnt, dfn[N], rev[N], top[N];
int d[N], fa[N], si[N], son[N], wf[N];
int lca[18][N], sum_wf[N];
void dfs(int u, int fat) {
    si[u] = 1;
    fa[u] = fat;
    d[u] = d[fat] + 1;
    for (const auto& pr : g[u]) {
        int v, w;
        tie(v, w) = pr;
        if (v != fat) {
            wf[v] = wf[u] + w;
            dfs(v, u);
            si[u] += si[v];
            if (si[v] > si[son[u]])
                son[u] = v;
        }
    }
}
void dfs2(int u, int Top) {
    dfn[u] = ++cnt;
    rev[dfn[u]] = u;
    top[u] = Top;
    if (!son[u])
        return;
    dfs2(son[u], Top);
    for (const auto& pr : g[u]) {
        int v, w;
        tie(v, w) = pr;
        if (v != fa[u] && v != son[u])
            dfs2(v, v);
    }
}
inline auto LCA_points(int u, int v) {
    while (top[u] != top[v]) {
        if (d[top[u]] < d[top[v]])
            swap(u, v);
        u = fa[top[u]];
    }
    if (d[u] > d[v])
        swap(u, v);
    return u;
}
inline auto init() {
    dfs(1, 0);
    dfs2(1, 1);
    for (int i = 1; i <= n; ++i) {
        rt[i] = rt[i - 1];
        int u = i;
        // assert(top[1] == 1);
        while (top[u] != 1) {
            // assert(d[top[u]] >= d[top[1]]);
            // if (d[top[u]] < d[1])
            //     swap(u, v);
            pt::add(1, n, rt[i], dfn[top[u]], dfn[u], 1);
            u = fa[top[u]];
        }
        // assert((d[u] >= d[v]));
        // if (d[u] > d[v])
        //     swap(u, v);
        pt::add(1, n, rt[i], dfn[1], dfn[u], 1);
        lca[0][i] = i;
        sum_wf[i] = sum_wf[i - 1] + wf[i];
    }
    for (int j = 1; j <= __lg(n); ++j)
        for (int i = 1; i + (1 << j) - 1 <= n; ++i)
            lca[j][i] = LCA_points(lca[j - 1][i], lca[j - 1][i + (1 << j - 1)]);
}
inline auto LCA(int l, int r) {
    auto len = __lg(r - l + 1);
    return LCA_points(lca[len][l], lca[len][r - (1 << len) + 1]);
}
inline int query(int p, int p1, int p2) {
    int lca = LCA(p1, p2);
    auto lca_p = LCA_points(lca, p);
    // if (dfn[lca] >= dfn[p] && dfn[lca] < dfn[p] + si[p])
    //     assert(lca_p == p);
    // if (lca_p == p)
    //     assert(dfn[lca] >= dfn[p] && dfn[lca] < dfn[p] + si[p]);
    if (dfn[lca] >= dfn[p] && dfn[lca] < dfn[p] + si[p])
        return wf[lca] - wf[p];
    if (lca_p == 1 && lca != 1)
        return wf[p] + wf[lca];
    int num = p2 - p1 + 1;
    // int sum = sum_wf[p2] - sum_wf[p1 - 1];
    if (lca != lca_p)
        return wf[lca] + wf[p] - (wf[lca_p] << 1);

    //		int v=1;
    //		while(top[u]!=top[v]) {
    //			if(d[top[u]]<d[top[v]])	swap(u, v);
    //			pt::add(1,n,rt[i],dfn[top[u]], dfn[u],1);
    //		}
    //		if(d[u]>d[v])	swap(u, v);
    //		pt::add(1,n,rt[i],dfn[u],dfn[v],1);
    // assert(top[1] == 1);
    int u = p;
    auto check = [&](int k) {
        cerr << "CK " << pt::query(1, n, rt[p1 - 1], rt[p2], k) << endl;
        // assert(pt::query(1, n, rt[p1 - 1], rt[p2], k) <= num);
        return pt::query(1, n, rt[p1 - 1], rt[p2], k) > 0;
    };
    while (top[u] != 1) {
        // assert(d[top[u]] >= d[top[1]]);
        if (check(dfn[top[u]])) {
            int l = dfn[top[u]], r = dfn[u], res = -1;
            while (l <= r) {
                int mid = l + r >> 1;
                if (check(mid))
                    res = mid, l = mid + 1;
                else
                    r = mid - 1;
            }
            res = rev[res];
            // assert(d[p] >= d[res]);
            return wf[p] - wf[res];
        }
        u = fa[top[u]];
    }
    // assert(d[u] >= 1);
    // assert(check(dfn[1]));
    // assert(dfn[1] == 1);
    int l = 1, r = dfn[u], res = -1;
    while (l <= r) {
        int mid = l + r >> 1;
        if (check(mid))
            res = mid, l = mid + 1;
        else
            r = mid - 1;
    }
    res = rev[res];
    // assert(d[p] >= d[res]);
    return wf[p] - wf[res];
}
}  // namespace hc
bool ED;
signed main() {
    cerr << "MEM USE: " << (&ED - &ST) / 1e6 << " END MEM" << endl;
    // freopen("//?/i:/desktop/slv/cqyc-/memory1.in", "r", stdin);
    // freopen("//?/i:/desktop/slv/cqyc-/memory.out", "w", stdout);
    freopen("memory.in", "r", stdin);
    freopen("memory.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 1; i < n; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    hc::init();
    int lst = 0;
    while (m--) {
        int p, l, r;
        cin >> p >> l >> r;
        p ^= lst;
        l ^= lst;
        r ^= lst;
        lst = hc::query(p, l, r);
        cout << lst << '\n';
    }
    return 0;
}
